<template>
	<view class="tab-home-page">
		<image v-if="commonConfigs && commonConfigs.domainFrontFileLink"
			:src="`${commonConfigs.domainFrontFileLink}/files/images/page-bg.png`" class="bg"
			style="width: 100vw; height: 100vh;" mode=""></image>
		
		<scroll-view scroll-y :scroll-top="scrollTop" @scroll="pageScrollFun" @scrolltolower="scrolltolower"
			class="home-page" :style="{
				top: commonNavHeight,
				height: `calc(100vh - ${commonNavHeight})`
			}">
			<view class="carousel-box">
				<swiper class="carousel-box-img mx-auto" @change="swiperChange" :autoplay="true" :interval="3000" :duration="500"
					:circular="true">
					<swiper-item v-for="(item, index) in bannerImgList" @click="gooGoodsPage(item, index)" :key="index">
						<image :style="{
								'z-index': 10,
								'opacity': currentSwiperImgIndex === index ? 1 : 0,
								'transition': 'all 1s',
							}" class="carousel-box-border absolute" v-if="commonConfigs && commonConfigs.domainFrontFileLink"
							:src="item.bg_image || `${commonConfigs.domainFrontFileLink}/files/images/home/swiper-bg.png`"
							mode="aspectFill" />
							
						<image :style="{
								'z-index': 10,
								'opacity': currentSwiperImgIndex === index ? 1 : 0.3,
								'transition': 'all 3s',
							}" class="carousel-box-cover absolute" style="z-index: 20" :src="item.image" mode="aspectFill" />
					</swiper-item>
				</swiper>
			</view>
			
			<view class="com-bullet-chat relative" v-if="tabCurrentIndex === 'tabHome'">
				<image class="bg" 
				style="width: 100%;height: 275rpx;left: -20rpx;"
				v-if="commonConfigs && commonConfigs.domainFrontFileLink"
				:src="`${commonConfigs.domainFrontFileLink}/files/images/newerbornZone/bullet-chat-bg.png`" />
				
				<comBulletChat v-if="isHomeShowing" :key="timeLenStr" :bulletChatRecordData="bulletChatRecordData" @getLastBulletChatFun="getLastBulletChatFun" 
				useSence="tabHome"
				/>
			</view>

			<view class="flex module-box flex-direction-column flex-justify-content-between">
				<view class="module-box-content flex flex-justify-content-between">
					<image 
					class="module-box-item"
					v-if="commonConfigs && commonConfigs.domainFrontFileLink"
					@click="gooNavPage('secondary/descRulePage/descRulePage?ruleTitle=限时活动&ruleType=40')"
					:src="`${commonConfigs.domainFrontFileLink}/files/images/home/activity-bg-img.png`" 
					mode=""></image>
					
					<image
					class="module-box-item"
					v-if="commonConfigs && commonConfigs.domainFrontFileLink"
					@click="gooNavPage('secondary/descRulePage/descRulePage?ruleTitle=新手攻略&ruleType=43')"
					:src="`${commonConfigs.domainFrontFileLink}/files/images/home/new-bg-novice.png`" 
					mode=""></image>
					
					<image
					class="module-box-item"
					v-if="commonConfigs && commonConfigs.domainFrontFileLink"
					@click="gooNavPage('secondary/invitePage/invitePage', 2)"
					:src="`${commonConfigs.domainFrontFileLink}/files/images/home/invite-bg-img.png`" mode=""></image>
					
					<image
					class="module-box-item"
					v-if="commonConfigs && commonConfigs.domainFrontFileLink"
					@click="gooNavPage('secondary/signInPage/signInPage', 2)"
					:src="`${commonConfigs.domainFrontFileLink}/files/images/home/signin-bg-img.png`" mode=""></image>
				</view>
				
				<view class="module-view flex flex-justify-content-between">
					<image class="module-view-preferential" v-if="commonConfigs && commonConfigs.domainFrontFileLink"
						:src="`${commonConfigs.domainFrontFileLink}/files/images/home/module-preferential-img.png`" mode=""
						@click="toRedirectPage('tabWelfare')"
						></image>

					<view class="module-view-item module-box-swiper">
						<swiper v-if="newpersonBannerList && newpersonBannerList.length" class="new-banner margin-auto relative" :autoplay="true" :interval="3000" :duration="500" :circular="true">
							<swiper-item v-for="(item, index) in newpersonBannerList" @click="gooNewGoodsPage(item, index)" :key="index">
								<comPlaceImage class="cover bg" style="position: absolute;width: 348rpx;height: 176rpx;top: 26rpx;right: 0rpx;" :lazyLoad="true"
									:src="item.reward_pool_show_cover" mode="aspectFill"></comPlaceImage>

								<view class="countdowntime flex flex-align-items-center absolute" style="z-index: 10;">
									<!-- <image class="bg" v-if="commonConfigs && commonConfigs.domainFrontFileLink"
										:src="`${commonConfigs.domainFrontFileLink}/files/images/home/home-time-bg.png`"
										mode="heightFix"></image> -->

									<view class="countdowntime-left relative">倒计时:</view>

									<view class="countdowntime-right relative">
										<view class="scroll-container">
										    <view class="scroll-content">
										      <text class="scroll-item">{{countDownTimeTxt}}</text>
										    </view>
										  </view>
									</view>
								</view>

								<view class="absolute" style="left: 100rpx;bottom: 28rpx;z-index: 10;">
									<image class="relative" style="width: 68rpx;height: 68rpx;"
										v-if="commonConfigs && commonConfigs.domainFrontFileLink && couponReceiveIconStatus"
										:src="`${commonConfigs.domainFrontFileLink}/files/images/home/new-person-receive-icon.png`"
										mode=""></image>
								</view>
							</swiper-item>
						</swiper>
						<image class="module-box-swiper-place relative" v-else @click="gooNewGoodsPage(0)"
							:src="`${commonConfigs.domainFrontFileLink}/files/images/home/module-swiper-img.png`"
							mode="heightFix"></image>
					</view>

				</view>
			</view>
			
			<!-- 大礼包 -->
			<view class="fixed" style="z-index: 1000; left: 50rpx; top: 250rpx;" @click="isShowGiftPopup = true">
				<comDragBox :x="systemInfo.windowWidth - 100" :y="250">
					<image class="sider-icon-gift" v-if="commonConfigs && commonConfigs.domainFrontFileLink && isShowGiftIcon"
						:src="`${commonConfigs.domainFrontFileLink}/files/images/home/big-gifs-icon.png`" mode=""
						></image>
				</comDragBox>
			</view>
			
			<!-- 联系客服 -->
			<view class="fixed" style="z-index: 1000; left: 50rpx; top: 320rpx;"@click="showGroupFun">
				<comDragBox :x="systemInfo.windowWidth - 100" :y="320">
					<image class="sider-icon-kefu" v-if="commonConfigs && commonConfigs.domainFrontFileLink"
						:src="`${commonConfigs.domainFrontFileLink}/files/images/home/concact-kefu-icon.png`" mode=""
						></image>
				</comDragBox>
			</view>
			
			<!-- 侧边栏按钮 -->
			<view class="home-sider-btns">
				<!-- 回到顶部 -->
				<image class="sider-icon-top" v-if="commonConfigs && commonConfigs.domainFrontFileLink && isShowSetTop"
					:src="`${commonConfigs.domainFrontFileLink}/files/images/home/back-top-icon.png`" mode=""
					@click="gooTopFun"></image>
			</view>
			
			<view class="tab-area" v-if="tabAreaFlag" style="height: 272rpx;"></view>
			<view class="tab-area" :class="tabAreaFlag ? 'fixed' : ''" ref="tabMax" :style="{position: 'sticky---', left: 0, top: commonNavHeight, 'z-index': 1000, }">
			
				<view class="tab-area-box flex flex-justify-content-center relative" style="background-image: url('../../../static/images/public_imgs/Rectangle.png');
					background-repeat: no-repeat;
					background-size: 93% 100%;
					background-position-x: 50%;">
					<view class="tabbar-item relative" @click="poolTypeChangeFun(item.type)"
						v-for="(item, index) in tabClassTypeList" :key="index"
						v-if="['openbox', 'challenge'].includes(item.aliasTxt) ? !commonOnline : true"
						>
						<image class="bg" v-if="commonConfigs && commonConfigs.domainFrontFileLink"
							:src="`${commonConfigs.domainFrontFileLink}/files/images/home/new-${item.aliasTxt}-tab-bg${tabPoolType === item.type ? '-active' : ''}.png`"
							mode=""></image>
					</view>
				</view>

				<view class="tab-area-item relative" v-if="tabAreaList && tabAreaList.length">
					<image class="bg" 
						style="width: 100%;height: 122rpx;top: -60rpx;"
						v-if="commonConfigs && commonConfigs.domainFrontFileLink"
						:src="`${commonConfigs.domainFrontFileLink}/files/images/home/tab-catetype-bg.png`" mode="">
					</image>
					<view class="tabbar-box relative">
						<view
							:class="['font-hanserif-bold tab-item-class relative', currentTypeId === item.id ? 'tab-item-class-active' : '']"
							v-for="(item, index) in tabAreaList" :key="item.id" 
							@click="tabChangFun(item.id, index)">
							
							<view class="relative flex tab-item-content flex-all-center"
							:style="{
								'min-width': index === currentTypeIndex ? '140rpx' : '134rpx',
								'height': index === currentTypeIndex ? '34rpx' : '34rpx',
							}"
							>
								<image class="bg" 			
									:src="`${commonConfigs.domainFrontFileLink}/files/images/home/tab-item-left.png`"
									mode=""
									v-show="commonConfigs && commonConfigs.domainFrontFileLink && index < currentTypeIndex"
									:style="{
										'z-index': -1,
										'min-width': index === currentTypeIndex ? '140rpx' : '134rpx',
										'height': index === currentTypeIndex ? '34rpx' : '34rpx',
									}"
									>
								</image>
								<image class="bg" 				
									 :src="`${commonConfigs.domainFrontFileLink}/files/images/home/tab-item-current.png`"
									mode=""
									v-show="commonConfigs && commonConfigs.domainFrontFileLink && index === currentTypeIndex"
									:style="{
										'z-index': -1,
										'min-width': index === currentTypeIndex ? '140rpx' : '134rpx',
										'height': index === currentTypeIndex ? '34rpx' : '34rpx',
									}"
									>
								</image>
								<image class="bg" 			
									:src="`${commonConfigs.domainFrontFileLink}/files/images/home/tab-item-right.png`"
									mode=""
									v-show="commonConfigs && commonConfigs.domainFrontFileLink && index > currentTypeIndex"
									:style="{
										'z-index': -1,
										'min-width': index === currentTypeIndex ? '140rpx' : '134rpx',
										'height': index === currentTypeIndex ? '34rpx' : '34rpx',
									}"
									>
								</image>
								
								<view :class="['relative', index === currentTypeIndex ? 'tab-item-name' : '']">{{ item.name }}</view>
								<view :class="['absolute', index === currentTypeIndex ? 'tab-item-name-border' : '']">{{ item.name }}</view>
							</view>
							
						</view>
					</view>
				</view>
				
			</view>

			<view class="reward-goods-box">
				<view class="goods-area relative" style="padding-bottom: 150rpx;">
					<view class="goods-area-list" v-show="tabPoolType === 1">
						<view class="flex-wrap flex-justify-content-between flex">
							<view class="goods-area-item relative" v-for="(item, index) in globalRewardList"
								:key="item.id" @click="gooDetailPage(item)">
								<comRewardItem :item="item" :tabPoolType="tabPoolType"></comRewardItem>
							</view>
						</view>
						<comLoadMore class="loadmore-txt" :loading="loading" :showLoadendTxt="showLoadendTxt"></comLoadMore>
					</view>
					<view class="goods-area-list" v-show="tabPoolType === 4">
						<view class="flex-wrap flex-justify-content-between flex">
							<view class="goods-area-item relative" v-for="(item, index) in openBoxRewardList"
								:key="item.id" @click="gooDetailPage(item)">
								<comRewardItem :item="item" :tabPoolType="tabPoolType"></comRewardItem>
							</view>
						</view>
						<comLoadMore class="loadmore-txt" :loading="loading" :showLoadendTxt="showLoadendTxt"></comLoadMore>
					</view>
					<view class="goods-area-list" v-show="tabPoolType === 5">
						<view class="flex-wrap flex-justify-content-between flex">
							<view class="goods-area-item relative" v-for="(item, index) in infiniteRewardList"
								:key="item.id" @click="gooDetailPage(item)">
								<comRewardItem :item="item" :tabPoolType="tabPoolType"></comRewardItem>
							</view>
						</view>
						<comLoadMore class="loadmore-txt" :loading="loading" :showLoadendTxt="showLoadendTxt"></comLoadMore>
					</view>
					<view class="goods-area-list" v-show="tabPoolType === 6">
						<view class="flex-wrap flex-justify-content-between flex">
							<view class="goods-area-item relative" v-for="(item, index) in challengeRewardList"
								:key="item.id" @click="gooDetailPage(item)">
								<comRewardItem :item="item" :tabPoolType="tabPoolType"></comRewardItem>
							</view>
						</view>
						<comLoadMore class="loadmore-txt" :loading="loading" :showLoadendTxt="showLoadendTxt"></comLoadMore>
					</view>
					<view class="relative" v-if="resLists && !resLists.length && !loading" style="z-index: 0">
						<comEmptyData></comEmptyData>
					</view>
				</view>

			</view>

		</scroll-view>
		
		<!-- 首页弹框轮播图 -->
		<comNewPersonPopup v-model="isShowGiftPopup" :reslists="giftList" :current="0" :isShowDots="false">
		</comNewPersonPopup>
	</view>
</template>

<script>
	import {
		getHomeBannerApi,
		geRewardPoolTypeApi,
		geRewardPoolChallengeTypeApi,
		geRewardPoolApi,
		geRewardPoolOpenBoxApi,
		geRewardPoolInfiniteApi,
		geRewardPoolChallengeApi,
		getHomePersonPoolNewApi,
		getContentHomeApi,
		getCouponHomeApi,
		getRewardMessageLogApi,
	} from '@/setupproject/INTERFACE';

	import {
		setDayTimeFunFormat,
		setAsyncFunWait,
		setNavigateFunTo,
		setJumpFunTo
	} from '@/setupproject/TOOLS_FUN.js';
	import paging from '@/inmixed/paging.mixin.js';

	export default {
		name: 'tabHome',
		mixins: [paging],
		props: {
			tabCurrentIndex: {
				type: String,
				default: () => ''
			},
			isHomeShowing: {
				type: Boolean,
				default: () => false
			},
			scene: String | Number
		},
		data() {
			const systemInfo = uni.getSystemInfoSync()
			return {
				systemInfo,
				
				bannerImgList: [],
				currentSwiperImgIndex: 0,

				tabAreaList: [],
				currentTypeId: 0,
				currentTypeIndex: 0,
				goodProductList: [],
				tabPoolType: 5,
				tabClassTypeList: [
					{
						type: 5,
						name: '飞机赏',
						aliasTxt: 'infinite'
					},
					{
						type: 1,
						name: '全局赏',
						aliasTxt: 'all'
					},
					{
						type: 4,
						name: '开箱',
						aliasTxt: 'openbox',
					},
					{
						type: 6,
						name: '闯关',
						aliasTxt: 'challenge',
					},
				],
				
				loading: true,
				timeLenStr: new Date().getTime(),
				
				giftList: [],
				isShowGiftPopup: false,
				isShowGiftIcon: false,

				// 全局赏
				globalRewardList: [],
				globalRewardPage: 1,
				globalRewardTypeList: [],
				globalRewardTypeId: '',
				
				// 开箱
				openBoxRewardTypeList: [],
				openBoxRewardPage: 1,
				openBoxRewardList: [],
				openBoxRewardTypeId: '',

				// 飞机赏
				infiniteRewardTypeList: [],
				infiniteRewardPage: 1,
				infiniteRewardList: [],
				infiniteRewardTypeId: '',
				
				// 闯关
				challengeRewardTypeList: [],
				challengeRewardPage: 1,
				challengeRewardList: [],
				challengeRewardTypeId: '',

				newpersonBannerList: [],
				couponReceiveIconStatus: false,
				freeReceiveIconStatus: false,
				countDownTimeTxt: '0天 00:00:00',
				timer: null,

				tabAreaTop: 0,
				tabAreaFlag: false,

				isShowSetTop: false,
				oldScrollTop: 0,
				scrollTop: 0,

				isFromNewPoolBack: false,
				setTopFlag: false,
				
				bulletChatRecordData: [],
				timeLenStr: new Date().getTime(),
			};
		},
		async created() {
			uni.$on('update', async (tabCurrentIndex) => {
				if (tabCurrentIndex === 'tabHome') {
					await setAsyncFunWait(1000);
					await this.getBulletChatFun();

					if (!this.isFromNewPoolBack) return;

					await this.loadDataGetFun()
					await this.newbannerGetFun();
				}else{
					this.bulletChatRecordData = [];
				}
			});

			var that = this;

			const query = uni.createSelectorQuery().in(that);
			query.select('.tab-area').boundingClientRect((data) => {
				if (data) {
					that.tabAreaTop = data.top;
				}
			}).exec();
			if (that.tabAreaTop == 0) {
				that.tabAreaTop = 152;
			}
			
			await setAsyncFunWait(1000);
			await this.getBulletChatFun();
		},
		destroyed() {

		},
		computed: {
			commonConfigs() {
				return this.$store.getters.commonConfigs || {};
			},

			commonNavHeight() {
				return this.$store.getters.commonNavHeight + 'px';
			},

			commonOnline() {
				return this.$store.getters.commonOnline;
			},
			showLoadendTxt() {
				return this.isShowPageLoadedTxt && !this.loading && this.resLists.length ? true : false;
			},

			userInfo() {
				return this.$store.getters.userInfo;
			},
		},
		watch: {
			scene(v) {
				let scene = Number(this.scene);

				this.tabPoolType = scene || 5;
			}
		},
		methods: {
			getLastBulletChatFun(isReQuestFlag) {
				if (isReQuestFlag) {
					this.bulletChatRecordData = [];
					this.getBulletChatFun();
					this.$forceUpdate();
				}
			},
			
			async getBulletChatFun() {
				const {
					data,
					code
				} = await getRewardMessageLogApi();
				if (code !== 200) return;
				this.bulletChatRecordData = data.log_message_list || [];
			},
			
			async gooTopFun() {
				//视图重新渲染
				this.scrollTop = this.oldScrollTop;
				this.tabAreaFlag = false;
				this.$forceUpdate();

				this.$nextTick(() => {
					this.scrollTop = 0;
					this.setTopFlag = true;
				});
			},

			async initData() {
				if (this.tabPoolType === 1) {
					this.globalRewardList = [];
					this.globalRewardPage = 1;
				}
				
				if (this.tabPoolType === 4) {
					this.openBoxRewardList = [];
					this.openBoxRewardPage = 1;
				}

				if (this.tabPoolType === 5) {
					this.infiniteRewardList = [];
					this.infiniteRewardPage = 1;
				}
				
				if (this.tabPoolType === 6) {
					this.challengeRewardList = [];
					this.challengeRewardPage = 1;
				}

				if (this.pageloading) {
					await (this.pageloading = false);
					await (this.loading = true)
					await this.pagingInitFun(6);
					await this.resListsGetFun();
					await (this.loading = false)
					await (this.pageloading = true);
				}
			},
			pageScrollFun(ev) {
				const scrollTop = ev.detail.scrollTop;

				// #ifdef APP-PLUS
				this.tabAreaFlag = (scrollTop >= this.tabAreaTop + 144) ? true : false;
				// #endif

				// #ifndef APP-PLUS
				this.tabAreaFlag = (scrollTop >= this.tabAreaTop - this.$store.getters.commonNavHeight + 46) ? true :
					false;
				// #endif

				// 点击回到顶部
				if (this.setTopFlag && !this.scrollTop) {
					this.tabAreaFlag = false;
				}
				this.oldScrollTop = scrollTop;
				this.isShowSetTop = this.tabAreaFlag;
				this.setTopFlag = false;
			},

			// 父组件tabbar触发当前子组件事件
			async loadDataGetFun() {
				this.globalRewardList = [];
				this.globalRewardPage = 1;
				this.globalRewardTypeList = [];
				this.globalRewardTypeId = '';

				this.infiniteRewardList = [];
				this.infiniteRewardPage = 1;
				this.infiniteRewardTypeList = [];
				this.infiniteRewardTypeId = '';
				
				this.openBoxRewardList = [];
				this.openBoxRewardPage = 1;
				this.openBoxRewardTypeList = [];
				this.openBoxRewardTypeId = '';
				
				this.challengeRewardList = [];
				this.challengeRewardPage = 1;
				this.challengeRewardTypeList = [];
				this.challengeRewardTypeId = '';

				await this.poolTypeChangeFun(this.tabPoolType);
				await this.getHomeBannerApi();
				await this.newbannerGetFun();
				await this.setShowGiftFun();
			},

			async getHomeBannerApi() {
				const {
					data
				} = await getHomeBannerApi({
					scene: 1,
					pack_name: this.commonConfigs.appPackageName,
					version: this.commonConfigs.appPackageVer,
					platform: uni.getSystemInfoSync().platform,
				});
				this.bannerImgList = data.banner;
			},

			async newbannerGetFun() {
				const {
					data
				} = await getHomePersonPoolNewApi({
					scene: 1,
					is_banner: 1,
					pack_name: this.commonConfigs.appPackageName,
					version: this.commonConfigs.appPackageVer,
					platform: uni.getSystemInfoSync().platform,
				});
				
				if (!data) return;
				this.newpersonBannerList = data.rows;
				
				// #ifdef APP-PLUS
				if (this.newpersonBannerList.length) {
					this.tabAreaTop = 330;
				}
				// #endif
				
				this.couponReceiveIconStatus = data.coupon_red_hit;
				this.freeReceiveIconStatus = data.free_red_hit; 

				clearInterval(this.timer);
				if (data.min_remain_time) {
					this.countDownTimeTxt = setDayTimeFunFormat(data.min_remain_time || 0);

					this.timer = setInterval(() => {
						if (!data.min_remain_time) {
							clearInterval(this.timer);
						}

						this.countDownTimeTxt = setDayTimeFunFormat(data.min_remain_time || 0);
						data.min_remain_time--;
					}, 1000);
				} else {
					this.countDownTimeTxt = '已结束';
				}

			},

			async poolTypeChangeFun(type) {
				this.tabPoolType = type;

				if (this.tabPoolType === 1) {
					this.globalRewardList = [];
					this.globalRewardPage = 1;
				}
				
				if (this.tabPoolType === 4) {
					this.openBoxRewardList = [];
					this.openBoxRewardPage = 1;
				}

				if (this.tabPoolType === 5) {
					this.infiniteRewardList = [];
					this.infiniteRewardPage = 1;
				}
				
				if (this.tabPoolType === 6) {
					this.challengeRewardList = [];
					this.challengeRewardPage = 1;
				}
				
				if(this.tabPoolType === 6) {
					this.geRewardPoolChallengeTypeApi(type);
				}else{
					this.geRewardPoolTypeApi(type);
				}
			},
	
			async geRewardPoolTypeApi(type) {
				const {
					data,
					code
				} = await geRewardPoolTypeApi({
					pack_name: this.commonConfigs.appPackageName,
					version: this.commonConfigs.appPackageVer,
					platform: uni.getSystemInfoSync().platform,
					pool_type: type,
				});

				if (code !== 200) {
					return;
				}

				this.tabAreaList = data.reward_pool_type;
				this.currentTypeId = data.reward_pool_type[0]?.id;
				this.currentTypeIndex = 0;
				
				if (type === 1) {
					this.globalRewardTypeList = data.reward_pool_type
					this.globalRewardTypeId = data.reward_pool_type[0]?.id;
				}
				if (type === 2) {
					this.removeCardTypeList = data.reward_pool_type
					this.removeCardTypeId = data.reward_pool_type[0]?.id;
				}
				if (type === 5) {
					this.infiniteRewardTypeList = data.reward_pool_type
					this.infiniteRewardTypeId = data.reward_pool_type[0]?.id;
				}
				if (this.pageloading) {
					await (this.pageloading = false);
					await (this.loading = true)
					await this.pagingInitFun(6);
					await this.resListsGetFun();
					await (this.loading = false)
					await (this.pageloading = true);
				}
			},
			
			async geRewardPoolChallengeTypeApi(type) {
				const {
					data,
					code
				} = await geRewardPoolChallengeTypeApi({
					pack_name: this.commonConfigs.appPackageName,
					version: this.commonConfigs.appPackageVer,
					platform: uni.getSystemInfoSync().platform,
					pool_type: type,
				});
			
				if (code !== 200) {
					return;
				}
			
				this.tabAreaList = data.gyms_type;
				this.currentTypeId = data.gyms_type[0]?.id;
				this.currentTypeIndex = 0;
				
				if (type === 6) {
					this.challengeRewardTypeList = data.gyms_type;
					this.challengeRewardTypeId = data.gyms_type[0]?.id;
				}
				
				if (this.pageloading) {
					await (this.pageloading = false);
					await (this.loading = true)
					await this.pagingInitFun(6);
					await this.resListsGetFun();
					await (this.loading = false)
					await (this.pageloading = true);
				}
			},
			
			// 获取列表
			async listsGetFun() {
				if(!this.currentTypeId) return;
				
				this.loading = true;
				let tempPage;
				if (this.tabPoolType === 1) {
					tempPage = this.globalRewardPage;
				} else if (this.tabPoolType === 5) {
					tempPage = this.infiniteRewardPage;
				} else if (this.tabPoolType === 4) {
					tempPage = this.openBoxRewardPage;
				} else if (this.tabPoolType === 6) {
					tempPage = this.challengeRewardPage;
				}
				
				let params = {
					...this.pageInfoObj,
					page: tempPage,
					pack_name: this.commonConfigs.appPackageName,
					version: this.commonConfigs.appPackageVer,
					platform: uni.getSystemInfoSync().platform,
					// reward_pool_type_id: this.currentTypeId,
					// gyms_type_id: this.currentTypeId,
				};

				// 全局赏
				let res = null;
				
				if(this.tabPoolType == 1) {
					params.reward_pool_type_id = this.currentTypeId;
					res = await geRewardPoolApi(params);
				}
				
				if(this.tabPoolType == 4) {
					params.reward_pool_type_id = this.currentTypeId;
					res = await geRewardPoolOpenBoxApi(params);
				}
				
				if(this.tabPoolType == 5) {
					params.reward_pool_type_id = this.currentTypeId;
					res = await geRewardPoolInfiniteApi(params);
				}
				
				if(this.tabPoolType == 6) {
					params.gyms_type_id = this.currentTypeId;
					res = await geRewardPoolChallengeApi(params);
				}

				setTimeout(() => {
					this.loading = false
				}, 100)
				
				const {
					code,
					msg,
					data
				} = res;
				
				if (code !== 200 || !data) {
					return;
				}
				if (this.tabPoolType === 1) {
					this.globalRewardList = [...this.globalRewardList, ...data.list]
					this.globalRewardPage = data.page + 1
				} else if (this.tabPoolType === 4) {
					this.openBoxRewardList = [...this.openBoxRewardList, ...data.list]
					this.openBoxRewardPage = data.page + 1
				} else if (this.tabPoolType === 5) {
					this.infiniteRewardList = [...this.infiniteRewardList, ...data.list]
					this.infiniteRewardPage = data.page + 1
				} else if (this.tabPoolType === 6) {
					this.challengeRewardList = [...this.challengeRewardList, ...data.list]
					this.challengeRewardPage = data.page + 1
				}
				data.resLists = data.list;
				data.count = data.total;
				return data;
			},

			async tabChangFun(id, index) {
				this.currentTypeIndex = index;
				this.currentTypeId = id;
				if (this.tabPoolType === 1) {
					this.globalRewardTypeId = id
					this.globalRewardList = []
					this.globalRewardPage = 1
				} else if (this.tabPoolType === 4) {
					this.openBoxRewardTypeId = id
					this.openBoxRewardList = []
					this.openBoxRewardPage = 1
				} else if (this.tabPoolType === 5) {
					this.infiniteRewardTypeId = id
					this.infiniteRewardList = []
					this.infiniteRewardPage = 1
				} else if (this.tabPoolType === 6) {
					this.challengeRewardTypeId = id
					this.challengeRewardList = []
					this.challengeRewardPage = 1
				}
				
				if (this.pageloading) {
					await (this.pageloading = false);
					await (this.loading = true)
					await this.pagingInitFun(6);
					await this.resListsGetFun();
					await (this.loading = false)
					await (this.pageloading = true);
				}
			},
			
			toRedirectPage(type) {
				return uni.redirectTo({
					url: `/pages/tabbar/tabbar?tabCurrentIndex=${type}`
				});
			},

			async gooNavPage(url, isOpen) {
				if (isOpen && isOpen === 1) {
					return uni.showToast({
						title: '暂未开放,敬请期待~~',
						icon: 'none'
					});
				}

				// #ifdef APP-PLUS
				if (isOpen && isOpen === 2 && (await this.$store.dispatch('SHOW_LOGIN_APP_GET_FUN'))) {
					return;
				}
				// #endif
				
				setNavigateFunTo(url);
			},
			
			async setShowGiftFun() {
				this.giftList = [];
				//  优惠券
				let couponData = await getCouponHomeApi();
				if (couponData && couponData.data && couponData.data.length) {
					this.giftList.push({
						sceneType: 1, // 优惠券
						data: couponData.data,
						reward_pool_floor_cover: `${this.commonConfigs.domainFrontFileLink}/files/images/newerbornZone/swiper-popup-coupon-bg.png`
					});
					this.isShowGiftIcon = true;
				}else{
					this.isShowGiftIcon = false;
				}
							
			},

			// 福利群
			showGroupFun() {
				this.$store.commit('SHOW_GROUP_SET_FUN', true);
			},

			// 跳转详情
			async gooDetailPage(item) {
				// #ifdef APP-PLUS
				// 验证是否已登录
				if (await this.$store.dispatch('SHOW_LOGIN_APP_GET_FUN')) return;
				// #endif
				
				this.isFromNewPoolBack = false; // 是否由新手专区返回
				const params = {
					id: item.id
				};
				//全局赏
				let boxSubIndex = (item.has_stock_box_list && item.has_stock_box_list[0]) || 1;
				params.boxSubIndex = boxSubIndex;
				if (this.tabPoolType === 1) {
					/* 
						type2 
						1 天梯竞技
						2 夺宝赏
						3 全局赏
						4 一番赏
					 */
					if (item.type2 === 1) {
						params.type = 'pk';
						setNavigateFunTo('secondary/globalRewardPage/globalRewardPage', params);
					} else if (item.type2 === 2) {
						params.type = 'treasure';
						setNavigateFunTo('secondary/globalRewardPage/globalRewardPage', params);
					} else if (item.type2 === 3) {
						params.type = 'all';
						setNavigateFunTo('secondary/globalRewardPage/globalRewardPage', params);
					} else if (item.type2 === 4) {
						params.type = 'aplus';
						setNavigateFunTo('secondary/globalRewardPage/globalRewardPage', params);
					}
				} else if (this.tabPoolType === 5) {
					// type 等级类型: null 非新手特区的普通池, 1优惠券，2初阶，3中阶，4高阶，5特惠
					if (item.type) {
						this.isFromNewPoolBack = true;
						const params = {
							id: item.activity_id,
							fromlink: 'newerSence',
							reward_pool_show_top_cover: item.reward_pool_show_top_cover,
							remain_time: item.remain_time,
							type: item.type,
						};
						return setNavigateFunTo('secondary/specialOfferZonePage/specialOfferZonePage', params);
					}

					setNavigateFunTo('secondary/infinitePage/infinitePage', params);
				} else if (this.tabPoolType === 4) {
					// 类型-5为DIY
					if(item.type2 === 5) {
						params.type = 'diybox';
						params.fromlink = 'diyBoxSence';
						
						return setNavigateFunTo('secondary/diyBoxPage/diyBoxPage', params);
					}
					
					// 类型-6为开箱
					if(item.type2 === 6) {
						params.type = 'lockbox';
						return setNavigateFunTo('secondary/globalRewardPage/globalRewardPage', params);
					}
					
				} else if (this.tabPoolType === 6) {
					// 类型 - 1爬塔 2闯关
					if(item.type2 === 1) {
						params.type = 'competition';
						params.fromlink = 'competitionSence';
						params.poolTypeSence = 'competitionSence';
						
						setNavigateFunTo('secondary/competitionPage/competitionPage', params);
					}
					
					if(item.type2 === 2) {
						params.type = 'challenge';
						params.fromlink = 'challengeSence';
						params.poolTypeSence = 'challengeSence';
						
						setNavigateFunTo('secondary/challengePage/challengePage', params);
					}
					
				} else {
					// type 等级类型: null 非新手特区的普通池, 1优惠券，2初阶，3中阶，4高阶，5特惠
					if (item.type) {
						this.isFromNewPoolBack = true;
						const params = {
							id: item.activity_id,
							fromlink: 'newerSence',
							type: item.type,
							remain_time: item.remain_time,
							reward_pool_show_top_cover: item.reward_pool_show_top_cover,
						};
						return setNavigateFunTo('secondary/specialOfferZonePage/specialOfferZonePage', params);
					}
				}
			},

			// 轮播图跳转
			gooGoodsPage(item, index) {
				return setJumpFunTo(item, index);
			},
			
			// 轮播图切换时间
			swiperChange(item) {
				this.currentSwiperImgIndex = item.detail.current;
			},

			// 新人优惠轮播图跳转
			async gooNewGoodsPage(item, index) {
				// #ifdef APP-PLUS
				// APP 登陆弹框及跳转
				if (await this.$store.dispatch('SHOW_LOGIN_APP_GET_FUN')) return;
				// #endif

				if (!item) {
					return uni.showToast({
						title: '暂未开放，敬请期待',
						icon: 'none',
						duration: 1000,
					})
				}

				this.isFromNewPoolBack = true;

				const params = {
					id: item.id,
					fromlink: 'newerSence',
					remain_time: item.remain_time,
					type: item.type,
					reward_pool_show_top_cover: item.reward_pool_show_top_cover,
				};
				
				setNavigateFunTo('secondary/specialOfferZonePage/specialOfferZonePage', params);
			},
		}
	};
</script>

<style scoped lang="scss">
	/deep/ .uni-scroll-view,
	.uni-scroll-view-content {
		overscroll-behavior: none;
	}

	/deep/ .uni-scroll-view-content {
		overscroll-behavior: none;
	}

	.home-page {
		color: #fff;
		top: 178rpx;
		position: relative;
		height: calc(100vh - 178rpx);
		overflow-y: auto;

		.carousel-box {
			margin: 0 auto;
			width: 710rpx;
			height: 340rpx;

			.carousel-box-img {
				width: 100%;
				height: 340rpx;
			}
			
			.carousel-box-border {
				width: 100%;
				height: 340rpx;
			}

			.carousel-box-cover {
				width: 702rpx;
				height: 332rpx;
				top: 4rpx;
				left: 4rpx;
			}
		}
		
		.com-bullet-chat {
			width: 100%;
			height: 100rpx;
		}

		.module-box {
			padding: 20rpx 24rpx 0;
			width: 100%;
			
			.module-box-content {
				margin-bottom: 36rpx;
				.module-box-item {
					width: 150rpx;
					height: 184rpx;
				}
			}

			.module-view {
				width: 100%;
				height: 204rpx;
				margin-bottom: 14rpx;

				.module-view-preferential {
					width: 348rpx;
					height: 198rpx;
					// height: 100%;
				}

				.module-view-item {
					width: 345rpx;
					height: 100%;

					&.module-box-swiper {
						width: 347rpx;
						height: 100%;

						.module-box-swiper-place {
							width: 348rpx;
							height: 176rpx;
							margin-top: 28rpx;
						}

						.new-banner {
							width: 345rpx;
							height: 204rpx;

							.cover {
								width: 345rpx;
								height: 204rpx;
							}

							.countdowntime {
								bottom: 26rpx;
								// right: 0rpx;
								right: -170rpx;
								width: 100%;
								height: 22rpx;
								.countdowntime-left {
									margin-left: 8rpx;
									margin-right: 4rpx;
									font-size: 18rpx;
									color: #FFFFFF;
									font-weight: 100;
								}

								.countdowntime-right {
									margin-left: 4rpx;
									font-size: 18rpx;
									font-weight: 500;
									color: #5A81FF;
									.scroll-container {
									  width: 100%;
									  overflow: hidden;
									  // height: 40px; /* 根据需要调整高度 */
									  // background-color: #007aff;
									}
									
									.scroll-content {
									  display: flex;
									  animation: scrollLeft 5s linear infinite; /* 动画效果 */
									}
									
									.scroll-item {
									  padding: 0 15rpx;
									  font-size: 18rpx;
									  color: #5A81FF;
									  white-space: nowrap;
									}
									
									/* 滚动动画 */
									@keyframes scrollLeft {
									  0% {
									    transform: translateX(100%);
									  }
									  100% {
									    transform: translateX(-100%);
									  }
									}
								}
							}
						}
					}

				}
			}

		}
		
		.sider-icon-gift {
			width: 160rpx;
			height: 160rpx;
		}
		
		.sider-icon-kefu {
			width: 160rpx;
			height: 160rpx;
		}
		
		.home-sider-btns {
			position: fixed;
			bottom: 360rpx;
			right: 0rpx;
			z-index: 1001;
			
			.sider-icon-top {
				width: 96rpx;
				height: 94rpx;
				margin-top: 26rpx;
				margin-left: 26rpx;
			}
		}


		.tab-area {
			width: 100%;
			&.sticky-style {
				color: #ff0;
			}
		}

		.tab-area-box {
			width: 100%;
			padding: 0 30rpx;
			margin: auto 0;
			z-index: 10;

			.tabbar-item {
				width: 148rpx;
				height: 200rpx;
				margin: 0 4rpx;

				.tab-name {
					width: 100%;
					height: 100%;
					font-size: 30rpx;
					font-weight: 500;
					color: #000000;

					&.active {
						font-size: 30rpx;
						font-weight: 500;
						color: #000000;
					}

				}
			}
			.tabbar-item:nth-child(1){
				width: 148rpx;
				height: 200rpx;
				margin: 0 4rpx;
			}
			.tabbar-item:nth-child(2){
				width: 152rpx;
				height: 204rpx;
				margin: -4rpx 4rpx;
			}
			.tabbar-item:nth-child(3){
				width: 162rpx;
				height: 196rpx;
				margin: 4rpx 4rpx;
			}
			.tabbar-item:nth-child(4){
				width: 148rpx;
				height: 202rpx;
				margin: -2rpx 4rpx;
			}
			
			.notice {
				width: 144rpx;
				height: 121rpx;
				top: -32rpx;
				right: -140rpx;
			}
		}

		.tab-area-item {
			white-space: nowrap;
			padding: 0rpx 30rpx 0rpx;
			width: 100%;
			height: 62rpx;

			::-webkit-scrollbar {
				width: 0;
				height: 0;
				color: transparent;
			}

			//隐藏滚动条
			.tabbar-box {
				top: -10rpx;
				height: 80rpx;
				text-align: center;
				overflow-x: auto;
			}

			.tab-item-class {
				top: 18rpx;
				display: inline-block;
				
				.tab-item-content {
					z-index: 100;
					font-size: 20rpx;
					color: #FFFFFF;
					
					.tab-item-name {
						color: rgba(255, 179, 0, 1);
						z-index: 2;
					}
					
					.tab-item-name-border {
						color: transparent;
						-webkit-text-stroke: 1rpx #5C2900;
						text-stroke: 1rpx #5C2900;
						z-index: 1;
					}
				}
				
			}
		}

		.goods-area {
			.goods-area-list {
				// background: rgba(0, 0, 0, 0.3);
				padding: 10rpx 20rpx 60rpx;
			}
		}
		
		
	}
</style>